package es.ucm.fdi.xtremeaudio.vista;

import java.awt.Graphics;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class JPanelImagen extends JPanel {

	private static final long serialVersionUID = 1L;

	private Image fondo;
	
	public JPanelImagen(String ruta) {
		if (ruta != null) {
            fondo = new ImageIcon(JPanelImagen.class.getClassLoader().getResource(ruta)).getImage();
        } else {
            fondo = null;
        }
	}

	public Image getFondo() {
		return fondo;
	}

	public void setFondo(Image fondo) {
		this.fondo = fondo;
	}
    
	@Override
    public void paint(Graphics g) {
        if (fondo != null) {
            g.drawImage(fondo,0,0,getWidth(),getHeight(),this);
            setOpaque(false);
        } else {
            setOpaque(true);
        }
        super.paint(g);
    }
}
